package com.gnerv.pabu.basic.core.controller;

import com.gnerv.pabu.basic.core.dto.CloudServiceDTO;
import com.gnerv.pabu.basic.core.entity.Result;
import com.gnerv.pabu.basic.core.service.ICloudService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 基础平台-微服务管理
 *
 * @author zhang
 * @date 2019/11/30
 **/
@Api(tags = "微服务管理")
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/api/manage/cloud/service")
public class CloudServiceController {

    @Resource
    private ICloudService cloudService;

    @ApiOperation("服务 状态")
    @RequestMapping(value = "/{appId}/{instanceId}/status/{status}", method = RequestMethod.GET)
    public Result updateCloudServiceStatus(@PathVariable(value = "appId") String appId,
                                           @PathVariable(value = "instanceId") String instanceId,
                                           @PathVariable(value = "status") String status) {
        cloudService.updateCloudServiceStatus(appId, instanceId, status);
        return Result.response();
    }

    @ApiOperation("服务 信息")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result listCloudService() {
        List<CloudServiceDTO> cloudServices = cloudService.listCloudService();
        return Result.response().data("cloudServices", cloudServices);
    }

}


